<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: liangwei
  Date: 2017/6/5
  Time: 16:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/base.jsp" %>
<html>
<head>
    <base href="${ctx}">
    <title>用户管理</title>
    <meta name=”renderer” content=”webkit”/>
    <link href="${ctx}/jquery-easyui-1.5.1/themes/default/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon-standard.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon-hamburg.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/css/head.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/css/index.css" rel="stylesheet" type="text/css">
    <script src="${ctx}/js/jquery.min.js"></script>
    <script src="${ctx}/js/HdUtil.js"></script>
    <script src="${ctx}/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
    <script src="${ctx}/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var wholeRoleId = "";
        var currRoleCode = "";
        var oldUserKeys = "";
        $(document).ready(function () {
            //管理人员的界面
            $("#manageDialog").dialog({
                title: "人员管理",
                width: 650,
                height: 450,
                closed: true,
                cache: false,
                modal: true
            });


            $("#rolesDialog").dialog({
                title: "新增人员",
                width: 320,
                height: 260,
                closed: true,
                cache: false,
                modal: true
            });

            $('#rolesTable').datagrid({
                url: '${ctx}/SysUser/getUser',
                method: "get",
                fit: true,
                queryParams: {
                    userName: ""
                },
                striped: true,
                rownumbers: true,
                pagination: true,
                singleSelect: true,
                sortName: "createTime",
                sortOrder: 'desc',
                pageSize: HdUtil.constant.PAGE_SIZE,
                columns: [[
                    {
                        width: '100',
                        title: '用户名称',
                        field: 'userName',
                        align: 'center',
                        halign: 'center'
                    }, {
                        width: '150',
                        title: '昵称',
                        halign: 'center',
                        align: 'center',
                        field: 'nickName'
                    }, {
                        width: '80',
                        title: '创建人',
                        align: 'center',
                        halign: 'center',
                        field: 'createUser'
                    }, {
                        width: '130',
                        title: '创建时间',
                        halign: 'center',
                        sortable: true,
                        align: 'center',
                        formatter: function (value) {
                            return new Date(value).format("yyyy-MM-dd hh:mm:ss");
                        },
                        field: 'createTime'
                    }, {
                        width: '80',
                        title: '修改人',
                        align: 'center',
                        halign: 'center',
                        field: 'updateUser'
                    }, {
                        width: '130',
                        title: '修改时间',
                        sortable: true,
                        align: 'center',
                        halign: 'center',
                        formatter: function (value) {
                            return new Date(value).format("yyyy-MM-dd hh:mm:ss");
                        },
                        field: 'updateTime'
                    }
                ]],
                toolbar: '#rolesTableToolBar',
                onLoadSuccess: function () {
                    $('.pwdBtn').linkbutton({
                        iconCls: 'icon-standard-server-edit',
                        plain: true
                    }).mousemove(function () {
                        $(this).find(".l-btn-text").css({"text-decoration": "underline", "color": "red"});
                    }).mouseout(function () {
                        $(this).find(".l-btn-text").css({"text-decoration": "none", "color": "#000"});
                    });
                    $('.disBtn').linkbutton({
                        iconCls: 'icon-standard-server-delete',
                        plain: true
                    }).mousemove(function () {
                        $(this).find(".l-btn-text").css({"text-decoration": "underline", "color": "red"});
                    }).mouseout(function () {
                        $(this).find(".l-btn-text").css({"text-decoration": "none", "color": "#000"});
                    });
                    $(".datagrid-btable").find("a").css({"height": "22px"});
                }
            });
        });



        function savePower() {
            var key = $("#frame")[0].contentWindow.savePower()
            if (key) {
                $("#powerDiaglog").dialog("close");
                HdUtil.messager.slide("保存成功");
                $("#rolesTable").datagrid("reload");
            } else {
                $("#powerDiaglog").dialog("close");
                HdUtil.messager.error("保存失败");
            }
        }

        //保存用户
        function saveRole() {
            if (!$("#rolesForm").form("validate")) {
                return false;
            }
            $.messager.progress();
            $("#rolesForm").form("submit", {
                url: "${ctx}/SysUser/saveUser",
                success: function (data) {
                    $.messager.progress('close');
                    if ("success" == data) {
                        $("#rolesDialog").dialog("close");
                        HdUtil.messager.slide("保存成功");
                        $("#rolesTable").datagrid("reload");
                    } else {
                        $("#manageForm").form("clear");
                        $("#rolesDialog").dialog("close");
                        HdUtil.messager.error("保存失败:" + data);
                    }
                }
            });
        }

        //新增角色页面跳转
        function add() {
            $("#rolesForm").form("clear");
            $("#rolesDialog").dialog("open").window("center");
        }

        //修改角色页面跳转
        function edit() {
            var selectRow = $("#rolesTable").datagrid("getSelected");
            if (selectRow) {
                $("#rolesForm").form("clear").form("load", selectRow);
                $("#rolesDialog").dialog("open").window("open");
            } else {
                HdUtil.messager.error("请选择要修改的记录");
            }
        }

        //删除人员
        function deleteRole() {
            var selectRow = $("#rolesTable").datagrid("getSelected");
            if (selectRow) {
                $.messager.confirm(HdUtil.constant.CONFIRM, HdUtil.constant.DELETE_CONFIRM, function (r) {
                    if (r) {
                        $.ajax({
                            method: "post",
                            url: "${ctx}/SysUser/deleteUserByUserId",
                            async: false,
                            data: {
                                userId: selectRow.userId
                            },
                            success: function (data) {
                                if (data == "success") {
                                    HdUtil.messager.slide(HdUtil.constant.DELETE_SUCCESS);
                                    $("#rolesTable").datagrid("reload");
                                } else {
                                    HdUtil.messager.error(data);
                                }
                            }, error: function (data) {
                                HdUtil.messager.error(data);
                            }
                        })
                    }
                });
            } else {
                HdUtil.messager.error("请选择要删除的记录");
            }
        }

    </script>
    <style type="text/css">
        textarea {
            font-family: "Microsoft YaHei";
        }
    </style>
</head>
<body>
<div id="rolesTableToolBar" style="height: 30px;">
    <form id="searchForm" style="align-items: center; margin-top:2px;">
        <span>用户名称:</span>
        <input name="userName" id="userName" data-options="prompt:'请输入用户名称'" class="easyui-textbox"/>&nbsp;
        <shiro:hasPermission name="role:query">
            <a class="easyui-linkbutton" iconCls="icon-search" onclick="searchRoles()">查询</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="role:add">
            <a class="easyui-linkbutton" iconCls="icon-add" onclick="add()">增加</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="role:edit">
            <a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit()">修改</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="role:delete">
            <a class="easyui-linkbutton" iconCls="icon-remove" onclick="deleteRole()">删除</a>
        </shiro:hasPermission>
    </form>
</div>
<table id="rolesTable" data-options="fit:true,border:false"></table>
<div id="rolesDialog" buttons="#user-dlg-buttons2">
    <form id="rolesForm" method="post">
        <table align="center">
            <br/>
            <tr>
                <td align="right" style="font-size: 12px;text-align:justify;">用户名称：</td>
                <td>
                    <input name="userId" type="hidden">
                    <input name="userName" class="easyui-textbox" data-options="required:true"/>
                </td>
            </tr>
            <tr>
                <td align="right" style="font-size: 12px;text-align:justify;">密码:</td>
                <td><input id="newPassword1" name="newPassword1" class="easyui-passwordbox"
                           data-options="required:true">
                </td>
            </tr>
            <tr>
                <td align="right" style="font-size: 12px;text-align:justify;">密码确认:</td>
                <td><input id="newPassword2" name="newPassword2" class="easyui-passwordbox"
                           data-options="required:true">
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="user-dlg-buttons2">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:saveRole();return false;">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="javascript:$('#rolesDialog').dialog('close');return false;">关闭</a>
</div>
</body>
</html>